473,480 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

"Clear All" items in a SELECT MULTIPLE box via JavaScript

Greetings,

I've been working on this for a few hours now. It seems to be a pretty
simple task but I keep running into "[element] has no properties".

I have a select box defined as follows:

<SELECT MULTIPLE NAME="myOptions[]" SIZE=5>
<OPTION VALUE="Blue">Blue</OPTION>
<OPTION VALUE="Red">Red</OPTION>
<OPTION VALUE="Green">Green</OPTION>
</SELECT>

The options are submitted to a PHP script which takes $myOptions as an
array for parsing.

All I want to do is give the user the ability to clear all of their
selected options. I don't want to actually remove the item from the
list, just de-select it. You get the idea... I've tried every
variation I can think of and I've been searching the web and usenet
for quite some time.

A function like this SHOULD do the job:

function uncheckAll() {
var obj = document.getElementById('myOptions');
for (var i=0; i < obj.options.length; i++) {
obj.options[i] = null;
}
}

But I keep getting told that "obj has no properties" on the "for"
line. I could use checkboxes and there wouldn't be any problems, but
eventually there will be 3 or 4 of these SELECT boxes on the page. I'd
like to keep the layout clean by using them instead of making big
lists of checkboxes.

This seems like a simple thing to do... but after 3+ hours of
searching, and trying many different methods, I'm still hitting a
brick wall. Granted I don't do much JavaScript these days, but I'd
sure like some help. If someone could give me a shove in the right
direction, it'd be appreciated.

- RK -

Jun 1 '07 #1
3 16374
Lee
Robert Kilroy said:
>
Greetings,

I've been working on this for a few hours now. It seems to be a pretty
simple task but I keep running into "[element] has no properties".

I have a select box defined as follows:

<SELECT MULTIPLE NAME="myOptions[]" SIZE=5>
<OPTION VALUE="Blue">Blue</OPTION>
<OPTION VALUE="Red">Red</OPTION>
<OPTION VALUE="Green">Green</OPTION>
</SELECT>

The options are submitted to a PHP script which takes $myOptions as an
array for parsing.

All I want to do is give the user the ability to clear all of their
selected options. I don't want to actually remove the item from the
list, just de-select it. You get the idea... I've tried every
variation I can think of and I've been searching the web and usenet
for quite some time.

A function like this SHOULD do the job:

function uncheckAll() {
var obj = document.getElementById('myOptions');
for (var i=0; i < obj.options.length; i++) {
obj.options[i] = null;
}
}

But I keep getting told that "obj has no properties"
You gave it the name "myOptions[]".
You didn't give it any id at all.
Why are you expecting document.getElementById('myOptions') to find it?
Give it an id, if you want to use getElementById().

See also:
http://www.jibbering.com/faq/#FAQ4_25
--

Jun 1 '07 #2
Ahhh! The one thing I didn't try... putting the brackets in as part of
the variable. I guess I assumed that MULTPLIE SELECTs were arrays by
default.

This function works in Firefox and IE6:

function uncheckAll() {
var obj = document.frmlisting.elements["myOptions[]"];
for (var loop=0; loop < obj.options.length; loop++) {
obj.options[loop].selected = false;
}
}

That's what I get for not keeping up with my JavaScript I guess...
Thanks!

(And yes, the Javascript FAQ is bookmarked) :)

On Jun 1, 5:05 pm, Lee <REM0VElbspamt...@cox.netwrote:
You gave it the name "myOptions[]".
You didn't give it any id at all.
Why are you expecting document.getElementById('myOptions') to find it?
Give it an id, if you want to use getElementById().

See also:http://www.jibbering.com/faq/#FAQ4_25

--

Jun 1 '07 #3
ASM
Robert Kilroy a écrit :
function uncheckAll() {
var obj = document.getElementById('myOptions');
for (var i=0; i < obj.options.length; i++) {
obj.options[i] = null;
obj.options[i].selected = false;
}
}

But I keep getting told that "obj has no properties"
yes that right ...
which property do you see in obj.options[i] ?
or : could options[i] be a property of obj ?

obj.options[i].text
obj.options[i].value
obj.options[i].selected
obj.options[i].id
obj.options[i].style
...
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Jun 2 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
12814
by: KENNY L. CHEN | last post by:
Dear experts, I have two tables in my Oracle 8i database: TEST (COL1,COl2,REC_NO) and TEST1 (COL1,COL2,REC_NO). Both tables are unique-indexed on (COL1,COL2,REC_NO). I think the following...
4
1675
by: Jack | last post by:
I finally discovered where all of the blue boxes in my IDE are coming from after, once again, accidently hitting "Mark All" in a Find in the Visual Studio.NET IDE. However, there is no "Unmark...
3
2123
by: Not Me | last post by:
Hi, Is there any criteria I can use in my where clause to say 'anything'? Maybe like the _ used in some languages? For my example, I want to use an inline-if, so if a checkbox is ticked I say...
7
2885
by: Jaime Stuardo | last post by:
Hi all.. I have a DataGrid with checkboxes. In the header I have a "check all" checkbox. I'm wondering if there is an easy way to check all checkboxes using that checkbox. I could do it using...
3
2889
by: Jimmy | last post by:
I use a combo box to filter the results of a form. Sql for combo box is... SELECT StatusPriority, Status FROM tblStatus UNION Select = 0 as AllChoice, "Show All" as Bogus From tblStatus ORDER...
1
1992
by: sherifffruitfly | last post by:
Hi, I've got a checked list box, and a "go' button on the form. Each item in the checked list box is associated with a program (say notepad, calc, etc.). When the user clicks "go", every item...
6
2049
jlandbw04
by: jlandbw04 | last post by:
Okay. Here's the deal. I have this assignment for college that has me completely puzzled. I need this assignment to do the following: 1. input 12 integers into an array from the user. 2. output...
4
1489
by: Pandu | last post by:
Hello: Our HR dept wants to allow users to download various HR forms from our comp intranet. But since there are over 20 forms, I need to allow users to select the files they want and then...
1
2114
by: Jenniferdb2 | last post by:
Hello All, create table a (i int); create table b(i int); insert into a values(1); ...
0
7048
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
6743
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6966
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5344
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4787
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2999
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2988
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
564
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.